package com.mooer.utils.ui;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.SimpleAdapter.ViewBinder;


public class BitmapViewBinder implements ViewBinder {
	@Override
	public boolean setViewValue(View view, Object data,
			String textRepresentation) {
		if ((view instanceof ImageView) && (data instanceof Bitmap)) {
			ImageView imageView = (ImageView) view;
			imageView.setVisibility(View.VISIBLE);
			Bitmap bitmap = (Bitmap) data;
			imageView.setImageBitmap(bitmap);
			return true;
		} else if ((view instanceof ImageView) && (data instanceof Drawable)) {
			ImageView imageView = (ImageView) view;
			imageView.setVisibility(View.VISIBLE);
			Drawable drawable = (Drawable) data;
			imageView.setBackgroundDrawable(drawable);
			return true;
		} else if ((view instanceof ImageView) && data == null) {
			ImageView imageView = (ImageView) view;
			imageView.setVisibility(View.GONE);
			return true;
		} else if ((view instanceof ImageView) && data instanceof Integer) {
			ImageView imageView = (ImageView) view;
			imageView.setVisibility(View.VISIBLE);
			Integer integer = (Integer) data;
			imageView.setBackgroundResource(integer);
			return true;
		}
		return false;
	}
}